model = Sketchup.active_model
selection = model.selection
entities = model.entities

cp = Sketchup::ComponentInstance  #要旋转的组件的引用

tfrt = Geom::Transformation  #旋转变量的引用

point = Geom::Point3d #旋转相对点

vector = Geom::Vector3d #旋转法向量

if selection[0].class == Sketchup::ComponentInstance
    cp = selection[0]
    cpid = cp.entityID
end

entity = model.find_entity_by_id(entity_id)

if selection[0].class == Sketchup::Edge
    edge = selection[0]
    point = edge.line[0]
    vector = edge.line[1]

    tfrt1 = Geom::Transformation.rotation(point, vector, 0.degrees)

    tfrt2 = Geom::Transformation.rotation(point, vector, 45.degrees)
    
    tfrt3 = Geom::Transformation.rotation(point, vector, 90.degrees)
    
end


entities.transform_entities(tfrt1,cp)
entities.transform_entities(tfrt2,cp)
entities.transform_entities(tfrt3,cp)


class FloatUpAnimation
    def nextFrame(view)
      new_eye = view.camera.eye
      new_eye.z = new_eye.z + 1.0
      view.camera.set(new_eye, view.camera.target, view.camera.up)
      view.show_frame
      return new_eye.z < 500.0
    end
  end

  model = Sketchup.active_model
  pages = model.pages
  status = pages.add "Page 1"
  status = pages.add "Page 2"


  class MyFrameChangeObserver

    def initialize(entID,edgeID)
        @entID = entID
        @edgeID = edgeID
        @ents = Sketchup.active_model.entities
        @ent = Sketchup.active_model.find_entity_by_id(@entID)
        @edge = Sketchup.active_model.find_entity_by_id(@edgeID)
        @point = @edge.line[0]
        @vector = @edge.line[1]
        @tfrt = Geom::Transformation.rotation(@point, @vector, 15.degrees)

    end
    def frameChange(from_page, to_page, percent_done)
      puts "From page #{from_page.name} to #{to_page.name} (#{percent_done * 100}%)"
      @ents.transform_entities(@tfrt,@ent)

    end
  end
  
  Sketchup::Pages.add_frame_change_observer(MyFrameChangeObserver.new(82198,80413))


  model = Sketchup.active_model
  selection = model.selection
  entities = model.entities
  #<Sketchup::Entities:0x00000271f2e9ecb8>
    model = Sketchup.active_model
    pages = model.pages
    status = pages.add "Page 1"
    status = pages.add "Page 2"
  #<Sketchup::Page:0x00000271f378f228>
  class MyFrameChangeObserver
    def initialize()
      @model = Sketchup.active_model
      @pages = @model.pages
    
    end
    def frameChange(from_page, to_page, percent_done)
      p @pages.selected_page.label
      p percent_done
      p from_page
      p to_page.label
      #puts "From page #{from_page.label} to #{to_page.label} (#{percent_done * 100}%)"
    end
  end
  id = Sketchup::Pages.add_frame_change_observer(MyFrameChangeObserver.new)
  1
  Sketchup::Pages.remove_frame_change_observer(id)


  #7-24小结
  #@pages.selected_page在起始两帧有延迟，可用to_page参数判断选中场景。
  #from_page参数在手动选中场景page时无效。只有在连续播放动画的第二幅场景后，才有from_page参数。